package com.example.demoes.controller;

import com.example.demoes.service.OmsOrderClientService;
import com.example.demoes.service.OmsOrderTemplateService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author rosszhang
 * @since 2023-12-09
 */
@Api(tags = "订单 Es Client  查询前端控制器")
@RestController
@RequestMapping("/order3")
@RequiredArgsConstructor
public class OmsOrderController3 {

    private final OmsOrderClientService omsOrderService;


    @ApiOperation(value = "根据用户名查询订单")
    @GetMapping("/getEsName")
    public Object getEsName(String memberUsername) throws IOException {
        return this.omsOrderService.getTemplateByMemberUsername(memberUsername);
    }

    @ApiOperation(value = "根据主键ID删除Es中的数据")
    @GetMapping("/deletedEsById")
    public Object deletedEsById(Long id) throws IOException {
        StringBuffer sb = new StringBuffer();
        long countFirst = this.omsOrderService.countTemplate();
        sb.append("Before Delete:").append(countFirst).append("\n");

        this.omsOrderService.deleteTemplateById(id);

        long countAfter = this.omsOrderService.countTemplate();
        sb.append("After deletion:").append(countAfter);
        return sb;

    }

    @ApiOperation(value = "统计Es中所有订单数量")
    @GetMapping("/count")
    public Object count() throws IOException {
        return this.omsOrderService.countTemplate();
    }
}
